﻿Imports Microsoft.Office.Tools.Ribbon

Public Class rMenu
    Dim WordApp As Microsoft.Office.Interop.Word.Application
    Dim docx As Microsoft.Office.Interop.Word.Document

    Private Sub rMenu_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles btNewProject.Click

        Dim WordApp As Microsoft.Office.Interop.Word.Application = New Microsoft.Office.Interop.Word.Application()
        Dim docx As Microsoft.Office.Interop.Word.Document = Globals.ThisAddIn.Application.Documents.Open("D:\CHINESE\tiengviet.docx")

        Try
            WordApp.Visible = True


            docx.Close(False)
            WordApp.Quit(False)
        Catch ex As Exception

        End Try

        If docx IsNot Nothing Then
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(docx)
        End If

        If WordApp IsNot Nothing Then
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(WordApp)
        End If

        GC.Collect()
    End Sub

    Private Sub Button2_Click(sender As Object, e As RibbonControlEventArgs) Handles Button2.Click
        ' Dim WordApp As Microsoft.Office.Interop.Word.Application = New Microsoft.Office.Interop.Word.Application()
        WordApp = New Microsoft.Office.Interop.Word.Application()
        docx = Globals.ThisAddIn.Application.Documents.Open("D:\CHINESE\tiengviet.docx")

    End Sub

    Private Sub Button3_Click(sender As Object, e As RibbonControlEventArgs) Handles Button3.Click
        docx.Close(False)
        WordApp.Quit(False)

        If docx IsNot Nothing Then
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(docx)
        End If

        If WordApp IsNot Nothing Then
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(WordApp)
        End If

        GC.Collect()
    End Sub


End Class
